<?php

/*
Process Add Pet (admin_add_pet.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$game=$_GET['game'];
$choose_species = $_POST['choose_species'];
$itemName = $_POST['itemName'];

$directoryName = "../images/user_images/opg_$game";
if (!file_exists($directoryName)) { mkdir($directoryName, 0777); }

$directoryName2 = "../images/user_images/opg_$game/pets";
if (!file_exists($directoryName2)) { mkdir($directoryName2, 0777); }

if ($HTTP_POST_FILES['petImage']['size'] >= 32000)
{
	die(header(error("admin_add_pet_look.php?game=$game", "Your image must be under 32,000 bytes (or 32kb)")));
}

if (!eregi("image/", $HTTP_POST_FILES['petImage']['type']))
{
	die(header(error("admin_add_pet_look.php?game=$game", "You can only use .gif, .jpg, and .jpeg files for images. Please convert the image to one of these file types.")));
}

$findPetLook  = fetch("SELECT id FROM pet_looks WHERE change_from = '$choose_species' AND item_name = '$itemName' AND game = '$game'");
if ($findPetLook[id])
{
	die(header(error("admin_add_pet_look.php?game=$game","That look already exsists.")));
}

$findPet      = fetch("SELECT id FROM pets2 WHERE id = '$choose_species' AND game = '$game'");
if (!$findPet[id])
{
	die(header(error("admin_add_pet_look.php?game=$game","That pet does not exsist.")));
}

$findItem = fetch("SELECT * FROM items2 WHERE id = '$itemName' AND game = '$game'");
if (!$findItem[id])
{
	die(header(error("admin_add_pet_look.php?game=$game","The item \"$itemName\" does not exsist!")));
}

mysql_query("INSERT INTO pet_looks VALUES ('', '$choose_species', '$itemName', '$game')");
$insert_id = mysql_insert_id();

$file = $HTTP_POST_FILES['petImage']['tmp_name'];
$dest = "../images/user_images/opg_$game/pets/pet2_$insert_id.gif";

copy($file, $dest);

header("Location: admin_add_pet_look.php?game=$game&error=The+new+pet+look+has+been+added!");

?>
